﻿using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

namespace JT.WEB.Migrations.ContextBaseMigrations
{
    public partial class b1 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "Abilities",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreateTime = table.Column<DateTime>(nullable: false),
                    Detectability = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Abilities", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "DetectionRanges",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreateTime = table.Column<DateTime>(nullable: false),
                    Range = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DetectionRanges", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "Messages",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Count = table.Column<int>(nullable: false),
                    Title = table.Column<string>(nullable: false),
                    Content = table.Column<string>(nullable: false),
                    MSLevel = table.Column<int>(nullable: false),
                    Processed = table.Column<bool>(nullable: false),
                    Read = table.Column<bool>(nullable: false),
                    SendTime = table.Column<DateTime>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Messages", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "StandardMethods",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreateTime = table.Column<DateTime>(nullable: false),
                    Method = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_StandardMethods", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "Summaries",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    SummaryName = table.Column<string>(nullable: false),
                    Preparer = table.Column<string>(nullable: false),
                    DebitDate = table.Column<DateTime>(nullable: false),
                    TotalDebitAmount = table.Column<double>(nullable: true),
                    TotalCreditAmount = table.Column<double>(nullable: true),
                    TotalSummary = table.Column<double>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Summaries", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "Years",
                columns: table => new
                {
                    YearId = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Years", x => x.YearId);
                });

            migrationBuilder.CreateTable(
                name: "MiddleTables",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreateTime = table.Column<DateTime>(nullable: false),
                    AbilityId = table.Column<int>(nullable: false),
                    RangeId = table.Column<int>(nullable: false),
                    MethodId = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MiddleTables", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MiddleTables_Abilities_AbilityId",
                        column: x => x.AbilityId,
                        principalTable: "Abilities",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_MiddleTables_StandardMethods_MethodId",
                        column: x => x.MethodId,
                        principalTable: "StandardMethods",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_MiddleTables_DetectionRanges_RangeId",
                        column: x => x.RangeId,
                        principalTable: "DetectionRanges",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "GeneralLedgers",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    SummaryId = table.Column<int>(nullable: true),
                    GLName = table.Column<string>(nullable: false),
                    Detail = table.Column<string>(nullable: true),
                    DebitAmount = table.Column<double>(nullable: true),
                    CreditAmount = table.Column<double>(nullable: true),
                    Footing = table.Column<double>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_GeneralLedgers", x => x.Id);
                    table.ForeignKey(
                        name: "FK_GeneralLedgers_Summaries_SummaryId",
                        column: x => x.SummaryId,
                        principalTable: "Summaries",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "TimeLines",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    YearId = table.Column<int>(nullable: false),
                    Months = table.Column<int>(nullable: false),
                    Content = table.Column<string>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_TimeLines", x => x.Id);
                    table.ForeignKey(
                        name: "FK_TimeLines_Years_YearId",
                        column: x => x.YearId,
                        principalTable: "Years",
                        principalColumn: "YearId",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.InsertData(
                table: "DetectionRanges",
                columns: new[] { "Id", "CreateTime", "Range" },
                values: new object[,]
                {
                    { 1, new DateTime(2019, 12, 13, 14, 23, 19, 297, DateTimeKind.Local).AddTicks(8963), "水和废水" },
                    { 2, new DateTime(2019, 12, 13, 14, 23, 19, 298, DateTimeKind.Local).AddTicks(8107), "空气和废气" },
                    { 3, new DateTime(2019, 12, 13, 14, 23, 19, 298, DateTimeKind.Local).AddTicks(8145), "室内空气、公共场所空气、工作场所空气" },
                    { 4, new DateTime(2019, 12, 13, 14, 23, 19, 298, DateTimeKind.Local).AddTicks(8149), "土壤、底质、固体废物" },
                    { 5, new DateTime(2019, 12, 13, 14, 23, 19, 298, DateTimeKind.Local).AddTicks(8150), "噪声" },
                    { 6, new DateTime(2019, 12, 13, 14, 23, 19, 298, DateTimeKind.Local).AddTicks(8152), "化肥" },
                    { 7, new DateTime(2019, 12, 13, 14, 23, 19, 298, DateTimeKind.Local).AddTicks(8154), "初级农产品" }
                });

            migrationBuilder.InsertData(
                table: "Years",
                column: "YearId",
                value: 2013);

            migrationBuilder.InsertData(
                table: "TimeLines",
                columns: new[] { "Id", "Content", "Months", "YearId" },
                values: new object[] { 1, "精泰检测成立了！", 8, 2013 });

            migrationBuilder.CreateIndex(
                name: "IX_GeneralLedgers_SummaryId",
                table: "GeneralLedgers",
                column: "SummaryId");

            migrationBuilder.CreateIndex(
                name: "IX_MiddleTables_AbilityId",
                table: "MiddleTables",
                column: "AbilityId");

            migrationBuilder.CreateIndex(
                name: "IX_MiddleTables_MethodId",
                table: "MiddleTables",
                column: "MethodId");

            migrationBuilder.CreateIndex(
                name: "IX_MiddleTables_RangeId",
                table: "MiddleTables",
                column: "RangeId");

            migrationBuilder.CreateIndex(
                name: "IX_TimeLines_YearId",
                table: "TimeLines",
                column: "YearId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "GeneralLedgers");

            migrationBuilder.DropTable(
                name: "Messages");

            migrationBuilder.DropTable(
                name: "MiddleTables");

            migrationBuilder.DropTable(
                name: "TimeLines");

            migrationBuilder.DropTable(
                name: "Summaries");

            migrationBuilder.DropTable(
                name: "Abilities");

            migrationBuilder.DropTable(
                name: "StandardMethods");

            migrationBuilder.DropTable(
                name: "DetectionRanges");

            migrationBuilder.DropTable(
                name: "Years");
        }
    }
}
